import React, { useContext, useMemo } from 'react';
import { Button, Space } from 'antd';
import { WorkflowHndTaskBtn } from '@/components/WorkflowCommonCopy';
import { IClarificationControllerContext } from '../../common/useOAContext';
import { getPosIDs, getTenantID, getUserID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
import { SHTH_CHECKSTATE } from '../../common/Format';
import { RollbackOutlined } from '@ant-design/icons';
import moment from 'moment';
export const DetailInfoBottomBtnView: React.FC = () => {
  /** 引入上下文 */
  const { taskId, styleFixCls, infoObj, reloadDetail, curRes, setInvalidState, setOAMessageRun } = useContext(IClarificationControllerContext);

  const allBtnsMemo = useMemo(() => {
    let isShowBtn = {
      revokeBtnDiv: false, //撤销按钮
      flowHandList: {}, //流程办理数据
    };

    /** 处理流程办理数据 */
    const taskType: string = `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1009`;
    const taskHandInfo: Record<string, any> = infoObj?.paramObject?.[taskType];
    if (
      taskHandInfo &&
      taskHandInfo?.mactivitiTaskList?.length > 0 &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneePositionID == getPosIDs() &&
      taskHandInfo?.mactivitiTaskList?.[0]?.assigneeID == getUserID()
    ) {
      isShowBtn['invalBoolBtn'] = true;
      isShowBtn['allBtnDiv'] = true;
      // isShowBtn['flowHandList'] = taskHandInfo?.mactivitiTaskList?.[0];
      isShowBtn['flowHandList'] = infoObj;
    }

    return isShowBtn;
  }, [infoObj]);

  return (
    <div className={`${styleFixCls}infoViewOA-bottomBtnBox-spaceItemBox`}>
      <Space>
        {/* 流程节点弹框 */}
        <WorkflowHndTaskBtn
          flowDetailInfo={infoObj}
          reloadCallback={reloadDetail}
          requestController={'purchaseSourceClarifyController'}
          clickSuccessFun={() => {
            setOAMessageRun({
              id: taskId,
              isRemark: 2,
              viewType: 1,
              endTime: moment()?.format('YYYY-MM-DD HH:mm:ss'),
            });
          }}
          flowBusinessType={`${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1009`}
          applyHeader={'apply'}
          revokeRequestUrl={'/purchaseSourceClarifyController/invalid'}
          revokeRequestState={`${getTenantID()}${ILoadMapTypeAll.PROCURECLARFY_STATE}`}
          isShowRevokeStateList={[`${getTenantID()}${ILoadMapTypeAll.PROCURECLARFY_STATE}1001`]}
          revokeTitle={infoObj?.packName}
          revokeSuccessCallback={reloadDetail}
        />
        {/* {(infoObj?.state == `${getTenantID()}${ILoadMapTypeAll.PROCURECLARFY_STATE}1001` ||
          (infoObj?.state == `${getTenantID()}${ILoadMapTypeAll.PROCURECLARFY_STATE}1000` && infoObj?.checkState == SHTH_CHECKSTATE())) &&
          infoObj?.applyerID == getUserID() &&
          infoObj?.applyPositionID == getPosIDs() &&
          curRes?.['/purchaseSourceClarifyController/invalid'] && (
            <Button
              type="primary"
              danger
              // icon={<RollbackOutlined />}
              onClick={() => {
                setInvalidState({ isShow: true, resObj: infoObj });
              }}
            >
              撤销
            </Button>
          )} */}
      </Space>
    </div>
  );
};
